
// 着色
const btnColor = document.getElementById('btn-color')
const colorData = [
  {
    propertyName: 'isRed',
    color: 'color("rgba(255,50,50,1)")',
    data: [
      { id: 1, modelId: 408977, name: '道路1' }
    ]
  },
  {
    propertyName: 'isYellow',
    color: 'color("rgba(255,255,0,1)")',
    data: [
      { id: 2, modelId: 428048, name: '道路2' }
    ]
  }
]
btnColor.addEventListener('click', () => {
  const cesiumController = new CesiumController()
  cesiumController.addMouseOver3DTileFeature()
  cesiumController.setTilesetColor(quadtreeManager, colorData)
})

// 撒点

let entities = []
const btnMarker = document.getElementById('btn-marker')

btnMarker.addEventListener('click', () => {
  const cesiumController = new CesiumController()
  const targetTiles = []
  const monitorData = [
    { id: 1, modelId: 434927, name: '牌子' }
  ]
  // const tiles = quadtreeManager._selectedTiles
  const tiles = quadtreeManager.selectedTiles // madd: 暂时添加public selectedTiles 属性
  for (let i = 0; i < tiles.length; i++) {
    const tile = tiles[i]
    for (let j = 0; j < tile.content.featuresLength; j++) {
      const feature = tile.content.getFeature(j)
      const name = feature.getProperty('name')
      // const modelIds = feature.getProperty('modelIds')
      const modelIds = feature.getProperty('modelId')
      if (!modelIds) {
        return
      }
      // 找到测点模型
      let findDevice = false
      findDevice = monitorData.find(_ => modelIds ===_.modelId)
      if (findDevice) {
        // 设置信息
        feature.setProperty('type', 'device')
        feature.setProperty('deviceId', findDevice.id)
        targetTiles.push(tile)
        console.log(tile)
        console.log(feature)
        logFeatureProperties(feature)
      }
    }
  }
  entities = cesiumController.addMarkersToTiles(targetTiles, monitorData)
})

// 清除撒点

const btnCleanMarker = document.getElementById('btn-marker-clean')

btnCleanMarker.addEventListener('click', () => {
  const cesiumController = new CesiumController()
  cesiumController.removeMarkers(entities[0])
})

// 清除全部撒点

const btnCleanMarkerAll = document.getElementById('btn-marker-clean-all')

btnCleanMarkerAll.addEventListener('click', () => {
  const cesiumController = new CesiumController()
  cesiumController.removeAllMarkers()
})
